package com.zoe.onelink.core.autoconfigure;

import com.zoe.onelink.core.nfs.property.OnelinkNfsProperties;
import com.zoe.onelink.core.nfs.storage.NfsApi;
import com.zoe.onelink.core.nfs.storage.impl.LocalStorageNfsImpl;
import com.zoe.onelink.core.util.NfsUtil;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.core.env.Environment;

/**
 * <p>标题: </p>
 * <p>描述: </p>
 * <p>版权: Copyright (c) 2022</p>
 * <p>公司: 智业软件股份有限公司</p>
 *
 * @version: 1.0
 * @author: ruansheng
 * @date: 2022-04-24
 */
@Configuration
@Import(NfsUtil.class)
@EnableConfigurationProperties(OnelinkNfsProperties.class)
public class OnelinkNfsAutoConfiguration {

    @Bean
    @ConditionalOnMissingBean
    public NfsApi<?> localStorageNfs(Environment env, OnelinkNfsProperties onelinkNfsProperties) {
        String property = env.getProperty("spring.application.name");
        String urlPrefix = onelinkNfsProperties.getServer() + onelinkNfsProperties.getPath();
        return new LocalStorageNfsImpl(urlPrefix, property);
    }

}
